<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      var lowestCommonAncestor = function (root, p, q) {
        return postOrder(root)
        function postOrder(root) {
          if (!root) return null
          if (root == p || root == q) return root
          let left = postOrder(root.left)
          let right = postOrder(root.right)
          if (left && right) return root
          if (left) return left
          if (right) return right
          //当前节点没有满足的的子树没有满足条件的 直接return null
          return null
        }
      }
    </script>
  </body>
</html>
